package com.jqb.struts2lab02.util;

import java.util.Map;

import ognl.DefaultTypeConverter;

import com.jqb.struts2lab02.bean.User;

public class UserDefaultConverter extends DefaultTypeConverter {

	@Override
	@SuppressWarnings("rawtypes")
	public Object convertValue(Map context, Object value, Class toType) {
		if (toType == User.class) {
			System.out.println("toUser...");
			String[] userinfos = (String[]) value;
			String[] userinfo = userinfos[0].split(",");
			User user = new User();
			user.setUsername(userinfo[0]);
			user.setPassword(userinfo[1]);
			return user;
		} else if (toType == String.class) {
			System.out.println("toString...");
			User user = (User) value;
			return user.getUsername() + "---" + user.getPassword();
		}
		return null;

	}

}
